import { saveAs } from "file-saver";
import { ElMessage } from "element-plus";

/**
 * 文件导出
 * @param response
 * @param filename
 */
export async function downloadFile(response: any, filename: string) {
  const isBlob = response.type !== 'application/json';
  if (isBlob) {
    const blob = new Blob([response]);
    saveAs(blob, filename);
  } else {
    ElMessage.error('文件导出失败');
  }
}
